#pragma once
#include <fstream>
#include "service\storage\StorageService.h"

// forward declarations
class BaseModel;

class BaseFileService : public StorageService {
public:

  // Constructors and deconstructor
  BaseFileService();
  explicit BaseFileService(const std::string fname,
                           const std::ios::openmode=std::ios::out|std::ios::in);

  explicit BaseFileService(std::fstream& file);
  virtual ~BaseFileService();

  BaseFileService& Open(const std::string fname,
                        const std::ios::openmode=std::ios::out|std::ios::in);

  BaseFileService& Open(const char *fname,
                        const std::ios::openmode=std::ios::out|std::ios::in);

  BaseFileService& OpenOut(const std::string fname,
                           const std::ios::openmode=std::ios::out);

  BaseFileService& OpenOut(const char *fname,
                           const std::ios::openmode=std::ios::out);

  BaseFileService& OpenIn(const std::string fname,
                          const std::ios::openmode=std::ios::in);

  BaseFileService& OpenIn(const char *fname,
                          const std::ios::openmode=std::ios::in);

  BaseFileService& Close();
  virtual BaseFileService& Load(BaseModel* model) { return *this; }
  virtual BaseFileService& Save(const BaseModel& model) { return *this; }

protected:
  void set_file(std::fstream& file);
  std::fstream& file() ;

private:
  // pointer reference counter
  int refcount_;
  std::fstream* file_;
};